<script>
    $(document).ready(function() {
        $("#datepickerstart").datepicker({
            numberOfMonths: 1,
            onSelect: function(selected) {
                $("#datepickerend").datepicker("option", "minDate", selected)
            }
        });
        $("#datepickerend").datepicker({
            numberOfMonths: 1,
        });
    });
</script>

<!-- Right side column. Contains the navbar and content of the page -->
<aside class="right-side">

    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>List Of URLs</h1>
        <ol class="breadcrumb">
            <li><a href="<?php base_url(); ?>dashboard"><i class="fa fa-dashboard"></i> Home</a></li>
            <li><a href="<?php base_url(); ?>searchurl">Search Url</a></li>
            <li class="active">URLs</li>
        </ol>
    </section>
    <section class="content">
    <div class="box box-warning">
        <div class="box-header">
            <h3 class="box-title">Search By </h3> <div class="pull-right">
                <a href="<?php echo base_url() ?>searchurl/pdf" class="btn btn-primary" style="margin: 5px;">
                      <i class="fa fa-download"></i>  Generate Pdf    
                        </a>
            </div></div>
        <form role="form" method="post" action="<?php echo base_url(); ?>searchurl/search_keyword">
            <div class="box-body">
                <div class="row">
                    <div class="col-xs-5">
                        <label for="">Long Url</label>
                        <input type="text" name="long_url" class="form-control" value="<?php echo set_value('long_url'); ?>"   placeholder="long Url">
                    </div>	
                    <div class="col-xs-4">
                        <label for="url">Short Url</label>
                        <input type="text" class="form-control"  name="short_url" value="<?php echo set_value('short_url'); ?>" placeholder="Short Url">
                    </div>
                    <div class="col-xs-5">
                        <label for="url">Start Date</label>
                        <input type="text" class="form-control" id="datepickerstart" name="create_timestart" placeholder="Start Date" value="<?php echo set_value('create_timestart'); ?>">
                    </div>
                    <div class="col-xs-4">
                        <label for="url">End Date</label>
                        <input type="text" class="form-control" id="datepickerend" name="create_timeend" placeholder="End Date" value="<?php echo set_value('create_timeend'); ?>">
                    </div>

                </div>
            </div><!-- /.box-body -->
            </br>
            <div class="box-footer">
                <button type="submit" class="btn btn-primary" name="submit">
                    Search
                </button>
                &nbsp; &nbsp;
                <a href="<?php echo base_url(); ?>searchurl" class="btn btn-primary"> Reset</a> &nbsp; &nbsp;
                  
            </div>
        </form>    
    </div>
        

    <!-- Main content -->
    
        <div class="row">
            <?php
            $msg = $this->session->flashdata('msg');
            if ($msg != '') {
                ?>
                <div class="alert alert-success alert-dismissable">
                    <i class="fa fa-check"></i>
                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                <?php echo "$msg" ?>
                </div>
            <?php } ?>
            <?php $msg = $this->session->flashdata('msg1');
            if ($msg != '') {
                ?>
                <div class="alert alert-danger alert-dismissable">
                    <i class="fa fa-ban"></i>
                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                <?php echo "$msg" ?>
                </div>
<?php } ?>
            <div class="col-xs-12">
                <div class="box">
                   
                    <div class="box-body table-responsive">
                        

                        <table id="example2" class="table table-bordered table-hover">
                            <thead>
                                <tr>

                                    <th>Short Url</th>
                                    <th>Long Url</th>
                                    <th>Date</th>
                                    <th width="5%">Total Hits</th>
                                    <th>Detail</th>
                                    <th width="15%">Action</th>
                                </tr>
                            </thead>
                            <tbody>
<?php
foreach ($results as $data) {
    ?> 
                                    <tr>

                                        <td><a target="_blank" href="<?php echo base_url(); ?>process?id=<?php echo $data->short_url; ?>"><?php echo base_url(); ?>process?id=<?php echo $data->short_url; ?></a></td>
                                        <td><div class="data" style="height:20px; width:350px; overflow:hidden;"><?php echo $data->long_url; ?></div></td>
                                        <td><?php echo date("d-M-Y h:m:sa", strtotime($data->create_time)); ?></td>
                                        <td align="center"><?php echo $data->hits; ?></td>
                                        <td align="center"><a href="<?php echo base_url() ?>reports/search_keyword?short=<?php echo $data->short_url; ?>"><i class="fa fa-fw fa-book"></i>Detail</a></td>
                                        <td>
                                            <a class="btn btn-primary btn-sm" href="<?php echo base_url() ?>searchurl/EditUrl?id=<?php echo $data->id; ?>" style="color: white;"><i class="fa fa-edit"></i>Edit</a> &nbsp;
                                            <a class="btn btn-danger btn-sm" id="confirm" href="<?php echo base_url() ?>searchurl/DeleteUrl?id=<?php echo $data->short_url; ?>" style="color: white;"><i class="fa fa-fw fa-trash-o"></i>Delete</a></td>
                                    </tr>
<?php } ?>

                            </tbody>
                        </table><div class="row"><div class="col-xs-6"><div class="dataTables_info" id="example2_info">
                           <?php
                            if($this->pagination->total_rows=='0'){ echo "<h3>No Record Found</h3>"; }else{
                           $param = $this->pagination->cur_page * $this->pagination->per_page;
                           if($param > $this->pagination->total_rows){
                           $param = $this->pagination->total_rows; }
                           if($this->pagination->cur_page=='0'){
                            $param = $this->pagination->total_rows;   
                           }
                           $off=$this->pagination->cur_page;
                           if($this->pagination->cur_page > '1'){
                               $off= (($this->pagination->cur_page * '10')-9);
                           }
                            echo "Showing ".$off."-".$param." of ". $this->pagination->total_rows." total results"; } ?>
                                </div></div><div class="col-xs-6"><div class="pull-right">
                                        <ul class="pagination" style="margin: 5px 0;">
                                        <li><?php echo $links ?></li></ul></div></div></div></div>
                    </div><!-- /.box-body -->
                </div><!-- /.box -->
            </div>
        </div>

    </section><!-- /.content -->
</aside><!-- /.right-side -->
<script>
    $("a#confirm").click(function(e) {
        e.preventDefault();
        var loc = $(this).attr('href');
        bootbox.confirm("Are you sure, You want to delete the Url ?", function(confirmed) {
            if (confirmed) {
                location.href = loc;
            }
        });
    });
</script> 
